<template>
  <div>
    <el-button type="primary" style="margin-bottom:0px;margin-top:5px;margin-left:0px" @click="backhome()">返回主页</el-button>
      <el-card style="margin-top:10px">
        
        <div>
          账号：<el-input placeholder=请输入内容 v-model=user.useraccount disabled></el-input>
          姓名：<el-input placeholder=请输入内容 v-model=user.userrname></el-input>
          身份证号：<el-input placeholder=请输入内容 v-model=user.userid></el-input>
          联系电话：<el-input placeholder=请输入内容 v-model=user.usernumber></el-input>
          钱包余额：<el-input placeholder=请输入内容 v-model=user.userwallet disabled></el-input>
          密码：<el-input placeholder=请输入内容 v-model=user.userpassword></el-input>
          个性签名：<el-input placeholder=请输入内容 v-model=user.usersignature></el-input>
          帐号状态：<el-switch v-model=newstate disabled></el-switch>
          <el-button style="margin-left:20%" type=primary @click="newUser()">确认更新信息</el-button>
        </div>
        <el-button style="float:left;margin-left:0%;margin-bottom:10px" type="danger" @click="deletepuser()">删除本账号</el-button>
      </el-card>
  </div>
</template>

<script>
export default {
data () {
      return {
          user: null,
          newstate:'',
          puserid:''
        
      }
    },
    created() {
        this.getUser()
    },
    methods: {

      //获取当前登录用户信息
      getUser() {
        this.getRequest('/user/info').then(resp => {
          this.user = resp
          this.puserid = resp.id
          if (resp.state=='true') {
            this.newstate=true
          }else {
            this.newstate=false
          }
          // console.log(resp)
        })
      },

      //确认更新信息
      newUser () {
        this.putRequest('/updata',this.user).then(resp => {
          if (resp) {
            this.getUser()
          }
        })
      },


      //返回主页
      backhome() {
        this.$router.replace('/puser')
      },

      //删除账号
      deletepuser() {
          this.$confirm('此操作将永久删除该账号, 是否继续?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          this.deleteRequest('/deleteaccount/'+this.puserid).then(resp => {
            this.$router.replace('/welcome')
          })
        }).catch(() => {
          this.$message({
            type: 'info',
            message: '已取消删除'
          });          
        });
          
      }
    }

}
</script>

<style lang=less scoped>
.el-card {
  margin-top:20px;

}
.el-input {
  width: 40%;
  margin-right: 100%;
  margin-bottom: 10px;
    min-width: 300px;
}
.el-button {
  margin-top:10px;
  margin-left: 16%;
}
</style>>
